<template>
  <!-- 添加或修改岗位对话框 -->
  <el-dialog
    title="维度打分"
    :visible.sync="visible"
    width="500px"
    append-to-body
    :close-on-click-modal="false"
  >
    <el-form label-width="100px">
      <el-row :gutter="20">
        <el-col :span="24" v-for="keyItem in scoreList" :key="keyItem.key">
          <el-form-item :label="keyItem.key">
            <el-input-number
              controls-position="right"
              v-model="keyItem.value"
              :min="0"
              :max="5"
            ></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addCandidateScore } from '@/api/system/candidate'
export default {
  dicts: ['sys_normal_disable', 'sys_project_platform'],
  props: {},
  mixins: [],
  components: {},
  data() {
    return {
      // 是否显示弹出层
      visible: false,
      // 表单参数
      form: {},
      projectScore: '[{"key": "专业度", "value": ""}, {"key": "视力", "value": ""}]',
      scoreList: [],
      artistId: '',
      projectId: ''
    }
  },
  computed: {
    // Your computed here
  },
  watch: {
    // Your watch here
  },
  methods: {
    open(row) {
      const tempScore = row.projectScore || ''
      this.scoreList = tempScore ? JSON.parse(tempScore) : []
      this.scoreList.forEach(element => {
        this.form[element.key] = element.value
      })
      // console.log(this.form)
      this.artistId = row.artistId
      this.projectId = row.projectId
      this.visible = true
    },
    // 取消按钮
    cancel() {
      this.visible = false
    },
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
    },

    /** 提交按钮 */
    submitForm() {
      console.log(this.scoreList)
      addCandidateScore({
        artistId: this.artistId,
        projectId: this.projectId,
        projectScore: JSON.stringify(this.scoreList)
      }).then(res => {
        this.$message.success('打分成功')
        this.visible = false
        this.$emit('update')
      })
    }
  },
  created() {
    // console.log('Component created');
  },
  mounted() {
    // console.log('Component created');
  }
}
</script>

<style scoped>
/* Your styles here */
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>
